From 861362c155f0f5494889c5709268b2ed5b0b27cd Mon Sep 17 00:00:00 2001 From: robertl Date: Fri, 30 Aug 2002 22:49:10 +0000 Subject: [PATCH] Make (optional) debug level runtime selectable. Handle magellan 'unable' messages so user knows their waypoints were munched. --- gpsbabel/defs.h | 1 + gpsbabel/magproto.c | 24 ++++++++++++++++++------ gpsbabel/main.c | 5 +++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index bdc7e0d44..f6e97fa6f 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -32,6 +32,7 @@ typedef struct { int synthesize_shortnames; + int debug_level; } global_options; extern global_options global_opts; diff --git a/gpsbabel/magproto.c b/gpsbabel/magproto.c index 0b5a64a54..197dbddd0 100644 --- a/gpsbabel/magproto.c +++ b/gpsbabel/magproto.c @@ -34,7 +34,7 @@ HANDLE comport; #endif -#define debug 0 +#define debug_serial (global_opts.debug_level > 1) char * termread(char *ibuf, int size); void termwrite(char *obuf, int size); @@ -48,6 +48,7 @@ static FILE *magfile_in; static FILE *magfile_out; static int magfd; static mag_rxstate magrxstate; +static int mag_error; static int last_rx_csum; static int found_done; static icon_mapping_t *icon_mapping; @@ -172,7 +173,7 @@ mag_writemsg(const char * const buf) int i; char obuf[1000]; - if (debug) { + if (debug_serial) { fprintf(stderr,"WRITE: $%s*%02X\r\n",buf, osum); } #if 0 @@ -278,24 +279,25 @@ mag_readmsg(void) isz = strlen(ibuf); if (isz < 5) { - if (debug) + if (debug_serial) fprintf(stderr, "SHORT READ %d\n", isz); return; } + mag_error = 0; while (!isprint(ibuf[isz])) isz--; isump = &ibuf[isz-1]; isum = strtoul(isump, NULL,16); if (isum != mag_pchecksum(&ibuf[1], isz-3)) { -if (debug) +if (debug_serial) fprintf(stderr, "RXERR %02x/%02x: '%s'\n", isum, mag_pchecksum(&ibuf[1],isz-5), ibuf); /* Special case receive errors early on. */ if (!got_version) { fatal("Magproto: bad communication. Check bit rate.\n"); } } - if (debug) { - fprintf(stderr, "READ: %s\n", ibuf); + if (debug_serial) { + fprintf(stderr, "READ: %s\n", ibuf); } if (IS_TKN("$PMGNCSM,")) { last_rx_csum = strtoul(&ibuf[9], NULL, 16); @@ -309,6 +311,13 @@ if (debug) mag_verparse(ibuf); return; } + mag_error = 0; + if (IS_TKN("$PMGNCMD,UNABLE")) { + fprintf(stderr, "Unable to send\n"); + found_done = 1; + mag_error = 1; + return; + } if (IS_TKN("$PMGNCMD,END") || is_file && feof(magfile_in)) { found_done = 1; return; @@ -744,6 +753,9 @@ mag_waypt_pr(waypoint *waypointp) mag_writemsg(obuf); if (!is_file) { mag_readmsg(); + if (mag_error) { + fprintf(stderr, "Protocol error Writing '%s'\n", obuf); + } } } diff --git a/gpsbabel/main.c b/gpsbabel/main.c index 4ec9cc2d7..ff25b16bb 100644 --- a/gpsbabel/main.c +++ b/gpsbabel/main.c @@ -92,6 +92,11 @@ main(int argc, char *argv[]) case 's': global_opts.synthesize_shortnames = 1; break; + case 'D': + global_opts.debug_level = atoi(optarg); +// global_opts.debug_level = 999; + argn++; + break; case 'h': case '?': usage(argv[0]); -- 2.30.2